$(function(){
    getCurrRedirect();//初始化 顶部nav
})

/**
 * 获取地址栏参数值
 * @param name
 * @returns {null}
 * @constructor
 */
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

function setUlShow() {
    var uiEl = document.getElementsByClassName('ui')[0];
    uiEl.style.display = 'block';
}

function canelUlShow() {
    var uiEl = document.getElementsByClassName('ui')[0];
    uiEl.style.display = 'none';
}
//置顶图标显示
$('#top-back').hide();
$(".cndns-right").fadeOut();
$(window).scroll(function () {
    if ($(this).scrollTop() > 350) {
        $("#top-back").fadeIn();
        $(".cndns-right").fadeIn();
    }
    else {
        $("#top-back").fadeOut();
        $(".cndns-right").fadeOut();
    }
})

//置顶事件
function topBack() {
    $('body,html').animate({scrollTop: 0}, 300);
}
/**
 * 顶部nav样式
 */
function getCurrRedirect(){
    var i= l= nl= ne ="s font nav_font ";//公共class样式
    var uri=getCurrUri();
     if(uri.indexOf("/list")==0){
        l+="check";
     }else if(uri.indexOf("/newLife")==0){
        nl+="check";
     }else if(uri.indexOf("/newEntrust")==0){
        ne+="check";
     }else{
        i+="check";
     }
    var html=
    '<li><a href="/" class="'+i+'">首页</a></li>'
    +'<li><a href="/list" class="'+l+'">租房</a></li>'
    +'<li><a href="/newLife" class="'+nl+'">生活服务</a></li>'
    +'<li><a href="/newEntrust" class="'+ne+'">房屋委托</a></li>';
    var el=document.getElementById('sub-nav');
    if(null==el||typeof(el)==undefined || null==el){
        return;
    }
    el.innerHTML=html;
}

/**
 * 当前地址
 * 例如：/list
 * @returns {string}
 */
function getCurrUri(){
    var url=window.location.href;
    var host='http://'+window.location.host;
    var uri=url.replace(host,"");
    if(uri==''||typeof(uri)==undefined || null==uri){
        uri="/";
    }
    return uri;
}

/**
 * 登录点击
 */
function toLogin(){
   var uri=getCurrUri();
   window.location.href="/login/index?uri="+uri;
}

/**
 * 注册点击
 */
function toRegister(){
    var uri=getCurrUri();
    window.location.href="/register/index?uri="+uri;
}

/**
 * 退出点击
 */
function toLogout(){
    var uri=getCurrUri();
    window.location.href="/login/logout?uri="+uri;
}

